<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>管理员主页</title>
</head>
<body>
<h1>欢迎，管理员!</h1>
<% if (request.getParameter("message") != null) { %>
<p style="color:green;"><%= request.getParameter("message") %></p>
<% } %>
<% if (request.getParameter("error") != null) { %>
<p style="color:red;"><%= request.getParameter("error") %></p>
<% } %>
<h2>所有用户:</h2>
<table border="1">
    <tr>
        <th>ID</th>
        <th>用户名</th>
        <th>姓名</th>
        <th>邮箱</th>
        <th>部门</th>
        <th>职位</th>
        <th>角色</th>
        <th>入职日期</th>
        <th>操作</th>
    </tr>
    <% for (com.employeemanagementsystem.model.User user : (java.util.List<com.employeemanagementsystem.model.User>) request.getAttribute("users")) { %>
    <tr>
        <td><%= user.getId() %></td>
        <td><%= user.getUsername() %></td>
        <td><%= user.getFullName() %></td>
        <td><%= user.getEmail() %></td>
        <td><%= user.getDepartment() %></td>
        <td><%= user.getPosition() %></td>
        <td><%= user.getRole().equals("ADMIN") ? "管理员" : "员工" %></td>
        <td><%= user.getHireDate() %></td>
        <td>
            <form action="delete_user" method="post" style="display:inline;">
                <input type="hidden" name="userId" value="<%= user.getId() %>"/>
                <button type="submit">删除</button>
            </form>
        </td>
    </tr>
    <% } %>
</table>

<h2>待处理反馈:</h2>
<table border="1">
    <tr>
        <th>员工ID</th>
        <th>内容</th>
        <th>状态</th>
        <th>创建时间</th>
        <th>更新时间</th>
        <th>操作</th>
    </tr>
    <% for (com.employeemanagementsystem.model.Feedback feedback : (java.util.List<com.employeemanagementsystem.model.Feedback>) request.getAttribute("pendingFeedbacks")) { %>
    <tr>
        <td><%= feedback.getEmployeeId() %></td>
        <td><%= feedback.getContent() %></td>
        <td><%= feedback.getStatus().equals("PENDING") ? "待处理" : "已处理" %></td>
        <td><%= feedback.getCreatedAt() %></td>
        <td><%= feedback.getUpdatedAt() %></td>
        <td>
            <form action="process_feedback" method="post" style="display:inline;">
                <input type="hidden" name="feedbackId" value="<%= feedback.getId() %>"/>
                回复: <input type="text" name="response" required/>
                <button type="submit">处理</button>
            </form>
        </td>
    </tr>
    <% } %>
</table>

<h2>已处理反馈:</h2>
<table border="1">
    <tr>
        <th>员工ID</th>
        <th>内容</th>
        <th>状态</th>
        <th>回复</th>
        <th>创建时间</th>
        <th>更新时间</th>
    </tr>
    <% for (com.employeemanagementsystem.model.Feedback feedback : (java.util.List<com.employeemanagementsystem.model.Feedback>) request.getAttribute("processedFeedbacks")) { %>
    <tr>
        <td><%= feedback.getEmployeeId() %></td>
        <td><%= feedback.getContent() %></td>
        <td><%= feedback.getStatus().equals("PROCESSED") ? "已处理" : "待处理" %></td>
        <td><%= feedback.getResponse() %></td>
        <td><%= feedback.getCreatedAt() %></td>
        <td><%= feedback.getUpdatedAt() %></td>
    </tr>
    <% } %>
</table>
<a href="logout">退出登录</a>
</body>
</html>
